package cn.edu.stu.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.io.FileNotFoundException;

/**
 * @author Karl
 * @Date 2022/12/11 - 20:03
 */

@Service
@ConfigurationProperties(prefix = "music")
public class ConfService {

    //静态资源的存放地
//    private String rootPath = this.getClass().getClassLoader().getResource("static").getPath()+ File.separator;
//    private String rootPath = new File(ResourceUtils.getURL("classpath:").getPath()).getParentFile().getParentFile().getParent()+File.separator+"myStatic"+File.separator;
    private String rootPath = null;

    //音乐文件的存放路径
//    private String filePath = "song"+File.separator+"mic"+File.separator;
    private String filePath = "mic"+File.separator;

    //是否需要验证码登录
    private boolean captchaOnOff = true;

    //验证码的格式
    private String captchaType = "math";

    //令牌中的默认过期，可在配置文件中更改,单位为秒
    private int expirationTime = 60;

    public ConfService() {
        String system = System.getProperty("os.name");
        if (system.contains("Windows")) {
            rootPath = "file:D:\\";
        } else {
            rootPath = "/music";
        }
    }

    public int getExpirationTime() {
        return expirationTime;
    }

    public void setExpirationTime(int expirationTime) {
        this.expirationTime = expirationTime;
    }


    public boolean selectCaptchaOnOff(){
        return captchaOnOff;
    }

    public String getCaptchaType(){
        return captchaType;
    }

    public boolean isCaptchaOnOff() {
        return captchaOnOff;
    }

    public void setCaptchaType(String captchaType) {
        this.captchaType = captchaType;
    }

    public void setCaptchaOnOff(boolean captchaOnOff) {
        this.captchaOnOff = captchaOnOff;
    }

    public void setRootPath(String rootPath) {
        this.rootPath = rootPath;
    }

    public String getRootPath() {
        return rootPath;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }
}
